{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAENCAYAAADgwHn9AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAHXVJREFUeJzt3Xt4VfWd7/H3NzdyBRJCwi0X5CICCpJ4Hett8Ear1NaqbT3i1B6eXpx5njPTnscZz9genemxnadVaz2n5VBb25mOl57OlLZaBNSKWi3Be1BJQHLhkgAJMSEQcvmeP/ZmGdIkbCDZK8n+vJ4nz15rr9/e+7t/SdZnr7V+a21zd0RERACSwi5ARERGDoWCiIgEFAoiIhJQKIiISEChICIiAYWCiIgEFAoiIhJQKIiISEChICIiAYWCiIgEUsIuYKjk5+d7aWlp2GWIiIRu8+bN+9x98sk8dsyEQmlpKRUVFWGXISISOjOrOdnHaveRiIgEFAoiIhJQKIiISEChICIiAYWCiIgExszoIxEZHdydjq4eDnd2c7gzetvVazp6f0dX97FtOnui7aLL+zzuUPT+zu4estKSGZ+RyoRBfoLlmalkp6WQlGRhd82IoFAQkZPi7jQdPEJNUzu1+9upbWqnZn87e9s6ONzZHVlp91mRH+7spqOr56RfMzXZSE9JZlxqMumpSaQfvU1JJisthUlZSaSlJNHW0U3LoU7qmw/RcqiTlkOddPcM/NXDScafhchxQyU9cpuTPrYCRaEgIgPq7O5h14FD1ERX+rXRAKhpaqeuqZ22jq5j2heOH8eU8emkpyYzMTPtoxV3ykcr8XG9VuTp/azcj13hJ5Oe8tF08kmufN2dg0ciQdHS3hkExYeHPpru+7OzV6B0DRIoZpAzLoUJmR8FxpTxGcwpzGZOQTZzC3OYPjFj1ASHQkEkwbUe7qRmf2QlX3PMiv8guw4cPuYTdlpKEkW5GZRMyuK8mXk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PYl4Htm9m/Ar9y9/gRfW0RkrLN+7vNB7j+uWI4p5AHZQA6Qbmb/fHS3TgyP7Yje9vSaPjp/vK2U+4AvEtlCecXM5sXweiIiiaQeKOo1PwPYNcj9xxVLKKwC/hH4N+Db7n6Xuy9298UxlRy7ViLBA4CZzXL3t93920AFoFAQETnWGuDW6Cik84EWd98NrAWuNLPc6AHmK6P3Hdegn9bN7Fagy91/YWbJwMtmdrm7P3tq76NfzwF3RrdA/hdwkZldBnQDW4Cnh+E1RURGLDP7d+BSIN/M6omMKEoFcPcfAk8RGbVZDbQDfxVd1mRm9xLZ9Q9wj7sPdsD6o9fU9ymIiIRH36cgIiIjlkJBREQCCgUREQkoFEREJKBQEBGRgEJBREQCCgUREQkoFEREJKBQEBGRgEJBREQCY+YyF2a2F6gJuw4RkRNU4u6Twy7iqDETCiIicuq0+0hERAIKBRERCSgUREQkoFAQEZGAQkFERAIKBRERCSgUREQkoFAQEZGAQkFERAL/HxhK9xwO7LrZAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7297dc1828>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from matplotlib.widgets import Slider\n",
    "\n",
    "# Create some random data\n",
    "x = np.linspace(0,100,1000)\n",
    "y = np.sin(x) * np.cos(x)\n",
    "\n",
    "left, bottom, width, height = 0.15, 0.02, 0.7, 0.10\n",
    "\n",
    "fig, ax = plt.subplots()\n",
    "\n",
    "plt.subplots_adjust(left=left, bottom=0.25) # Make space for the slider\n",
    "\n",
    "ax.plot(x,y)\n",
    "\n",
    "# Set the starting x limits\n",
    "xlims = [0, 1]\n",
    "ax.set_xlim(*xlims)\n",
    "\n",
    "# Create a plt.axes object to hold the slider\n",
    "slider_ax = plt.axes([left, bottom, width, height])\n",
    "# Add a slider to the plt.axes object\n",
    "slider = Slider(slider_ax, 'x-limits', valmin=0.0, valmax=100.0, valinit=xlims[1])\n",
    "\n",
    "# Define a function to run whenever the slider changes its value.\n",
    "def update(val):\n",
    "    xlims[1] = val\n",
    "    ax.set_xlim(*xlims)\n",
    "\n",
    "    fig.canvas.draw_idle()\n",
    "\n",
    "# Register the function update to run when the slider changes value\n",
    "slider.on_changed(update)\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAH1VJREFUeJzt3XmUVOW1/vHvFlFUiMigIoKtcQgNMrYIxqCJZkW9P3XdRFZM7o1GQZwnjNcp6hWN88UJZEZUFEVQQWUQRBAQ0AaZcSAaI4oRUcEJpGH//tiVFdI0dAFVfWp4Pmv1WvV2ne7ax5KHzVvnvK+5OyIiUlh2SboAERHJPIW7iEgBUriLiBQghbuISAFSuIuIFCCFu4hIAVK4i4gUIIW7iEgBUriLiBSgXZN64UaNGnlJSUlSLy8ikpfmzp37ubs3ru64xMK9pKSE8vLypF5eRCQvmdmH6RynaRkRkQKkcBcRKUAKdxGRAqRwFxEpQNWGu5nVMbM3zGyBmS0xs1uqOGZ3M3vazJab2RwzK8lGsSIikp50Ovf1wC/cvQ3QFjjJzDpVOqYb8KW7HwrcB9yV2TJFRGR7VBvuHr5JDWunvipv33Q68Gjq8SjgBDOzjFUpIlIoNm2Cioqsv0xac+5mVsvM5gOfAZPcfU6lQ5oCHwG4ewWwBmhYxe/pYWblZla+atWqnatcRCTfvPMOdOkCd9yR9ZdKK9zdfaO7twUOBDqaWatKh1TVpW+xOau7D3T3Mncva9y42husREQKw4YNEeht2sDMmTB4MKxbl9WX3K6rZdz9K2AqcFKl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QVys0MrMVwM3EB0W4e39iv91TgOXAd8A5yVRavTTO5QzgQjOrAL4HzszRBuKnwB+ARan5XYDrgeaQd+9LOueSL+9LE+BRM6tF/AU00t1frIkc0x2qIiIFKJenZUREZAcp3EVECpDCXUSkACncRUQKkMJdRKQAKdxFRAqQwl1EpAAp3EVECtD/B5m1cv7vneZxAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "020666f85eb0489c8ca45ebfb4820d31",
       "version_major": 2,
       "version_minor": 0
      },
      "text/html": [
       "<p>Failed to display Jupyter Widget of type <code>interactive</code>.</p>\n",
       "<p>\n",
       "  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n",
       "  that the widgets JavaScript is still loading. If this message persists, it\n",
       "  likely means that the widgets JavaScript library is either not installed or\n",
       "  not enabled. See the <a href=\"https://ipywidgets.readthedocs.io/en/stable/user_install.html\">Jupyter\n",
       "  Widgets Documentation</a> for setup instructions.\n",
       "</p>\n",
       "<p>\n",
       "  If you're reading this message in another frontend (for example, a static\n",
       "  rendering on GitHub or <a href=\"https://nbviewer.jupyter.org/\">NBViewer</a>),\n",
       "  it may mean that your frontend doesn't currently support widgets.\n",
       "</p>\n"
      ],
      "text/plain": [
       "interactive(children=(FloatSlider(value=2.0, description='f', max=5.0), Output()), _dom_classes=('widget-interact',))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<function __main__.func>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#from notebook import *\n",
    "from ipywidgets import interact\n",
    "#from IPython.html.widgets import *\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "p=np.arange(0,np.pi,0.05*np.pi)\n",
    "fig, ax = plt.subplots()\n",
    "l, = plt.plot(p,p, lw=2, color='red')\n",
    "#t=np.arange(0,1,0.1)\n",
    "def func(f):\n",
    "    l.set_ydata(np.sin(p*f))\n",
    "    fig.canvas.draw_idle()\n",
    "    #plt.plot(p,np.sin(2*np.pi*p*f))\n",
    "    #print('dfh')\n",
    "    #plt.show()\n",
    "interact(func,f=(0,5,0.1))\n",
    "plt.show(-"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3af4d53de4f54c699b73c22979ad03a0",
       "version_major": 2,
       "version_minor": 0
      },
      "text/html": [
       "<p>Failed to display Jupyter Widget of type <code>interactive</code>.</p>\n",
       "<p>\n",
       "  If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n",
       "  that the widgets JavaScript is still loading. If this message persists, it\n",
       "  likely means that the widgets JavaScript library is either not installed or\n",
       "  not enabled. See the <a href=\"https://ipywidgets.readthedocs.io/en/stable/user_install.html\">Jupyter\n",
       "  Widgets Documentation</a> for setup instructions.\n",
       "</p>\n",
       "<p>\n",
       "  If you're reading this message in another frontend (for example, a static\n",
       "  rendering on GitHub or <a href=\"https://nbviewer.jupyter.org/\">NBViewer</a>),\n",
       "  it may mean that your frontend doesn't currently support widgets.\n",
       "</p>\n"
      ],
      "text/plain": [
       "interactive(children=(FloatSlider(value=0.0, description='m', max=2.0, min=-2.0), FloatSlider(value=0.0, description='b', max=3.0, min=-3.0, step=0.5), Output(layout=Layout(height='350px'))), _dom_classes=('widget-interact',))"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%matplotlib inline\n",
    "from ipywidgets import interactive\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "def f(m, b):\n",
    "    plt.figure(2)\n",
    "    x = np.linspace(-10, 10, num=1000)\n",
    "    plt.plot(x, m * x + b)\n",
    "    plt.ylim(-5, 5)\n",
    "    plt.show()\n",
    "\n",
    "interactive_plot = interactive(f, m=(-2.0, 2.0), b=(-3, 3, 0.5))\n",
    "output = interactive_plot.children[-1]\n",
    "output.layout.height = '350px'\n",
    "interactive_plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pandas'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m------------------------------------\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0mTraceback (most recent call last)",
      "\u001b[0;32m<ipython-input-8-52eb3cc83736>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0mget_ipython\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun_line_magic\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'matplotlib'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'notebook'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mpandas\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      3\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mmatplotlib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpyplot\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mipywidgets\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mIPython\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdisplay\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mdisplay\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'pandas'"
     ]
    }
   ],
   "source": [
    "%matplotlib notebook\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "from ipywidgets import *\n",
    "from IPython.display import display\n",
    "from IPython.html import widgets\n",
    "plt.style.use('ggplot')\n",
    "\n",
    "NUMBER_OF_PINGS = 4\n",
    "\n",
    "# displaying the text widget\n",
    "text = widgets.Text(description=\"Domain to ping\", width=200)\n",
    "display(text)\n",
    "\n",
    "# preparing the plot \n",
    "data = pd.DataFrame()\n",
    "x = range(1,NUMBER_OF_PINGS+1)\n",
    "plots = dict()\n",
    "fig, ax = plt.subplots()\n",
    "plt.xlabel('iterations')\n",
    "plt.ylabel('ms')\n",
    "plt.xticks(x)\n",
    "plt.show()\n",
    "\n",
    "# preparing a container to put in created checkbox per domain\n",
    "checkboxes = []\n",
    "cb_container = widgets.HBox()\n",
    "display(cb_container)\n",
    "\n",
    "# add button that updates the graph based on the checkboxes\n",
    "button = widgets.Button(description=\"Update the graph\")\n",
    "\n",
    "# function to deal with the added domain name\n",
    "def handle_submit(sender):\n",
    "    # a part of the magic inside python : pinging\n",
    "    res = !ping -c {NUMBER_OF_PINGS} {text.value}\n",
    "    hits = res.grep('64 bytes').fields(-2).s.replace(\"time=\",\"\").split()\n",
    "    if len(hits) == 0:\n",
    "        print (\"Domain gave error on pinging\")\n",
    "    else:\n",
    "         # rebuild plot based on ping result\n",
    "        data = hits\n",
    "        data = data.astype(float)\n",
    "        plots, = ax.plot(x, data, label=text.value)\n",
    "        plt.legend()\n",
    "        plt.draw()\n",
    "        # add a new checkbox for the new domain\n",
    "        checkboxes.append(widgets.Checkbox(description = text.value, value=True, width=90))\n",
    "        cb_container.children=[i for i in checkboxes]\n",
    "        if len(checkboxes) == 1:\n",
    "            display(button)\n",
    "\n",
    "# function to deal with the checkbox update button       \n",
    "def on_button_clicked(b):\n",
    "    for c in cb_container.children:\n",
    "        if not c.value:\n",
    "            plots.set_visible(False)\n",
    "        else:\n",
    "            plots.set_visible(True)\n",
    "    plt.legend()\n",
    "    plt.draw()\n",
    "\n",
    "button.on_click(on_button_clicked)\n",
    "text.on_submit(handle_submit)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
